package models;

import play.db.ebean.Model;
import play.db.ebean.Model.Finder;

import java.util.*;
import javax.persistence.*;
 
import play.db.jpa.*;

@Entity
@Table(name = "ligne_commande")
public class LigneCommande extends Model {
	
	@Id
	@Column(name="id_lig_com")
	public Long idLigneCommande;
	@Column(name="qte_lig_com")
	public int quantite;
	@Column(name="montant_total_ligne_com")
	public double montantTotal;
	@ManyToOne
	@JoinColumn(name = "id_commande")
	public Commande commande;
	@ManyToOne
	@JoinColumn(name = "id_article")
	public Article article;
	
	public static Finder<Long, LigneCommande> find =
			new Finder<Long, LigneCommande>(Long.class, LigneCommande.class);
	
	public LigneCommande(int quantite, double montantTotal, Commande commande, Article article){
		//this.idLigneCommande=idLigneCommande;
		this.quantite=quantite;
		this.montantTotal=montantTotal;
		this.commande=commande;
		this.article=article;
	}
	
	public void augmenterQuantite() {
		quantite += 1;
		calcMontantTotal();
	}
	
	public void dimminuerQuantite() {
		quantite -= 1;
		calcMontantTotal();
	}
	
	private void calcMontantTotal() {
		montantTotal = article.prix_article * quantite;		
	}
}